<?php
error_reporting(E_ALL ^ E_NOTICE);

set_time_limit(0);
date_default_timezone_set("PRC"); //timezone

$db=mysql_connect("localhost","root","root"); 
mysql_select_db('faithwar',$db); 

//$db2=mysql_connect('192.168.0.17','root','root'); 
//mysql_select_db('faithwar',$db2); 
#$dateTime = date("Y-m-d",strtotime("-2 day"));
$dateTime = date("Y-m-d");

//$logdate =  mysql_query("SELECT DISTINCT date FROM `faithwar` where date = '$dateTime'",$db);

//while($dateTime = date("Y-m-d"))
//{
     
       //NewTenSeconds 新用户首次游戏时间 10秒 
    $NewTenSeconds_query = mysql_query("SELECT count(1)  FROM  deviceid   where date ='$dateTime' and   dayTotalTime between 6 and 10",$db);
    $NewTenSeconds = mysql_fetch_array($NewTenSeconds_query);
       //NewTwentySeconds 新用户首次游戏时间 20秒 
    $NewTwentySeconds_query = mysql_query("SELECT count(1)  FROM  deviceid   where date ='$dateTime' and   dayTotalTime between 11 and 20",$db);
    $NewTwentySeconds = mysql_fetch_array($NewTwentySeconds_query);
      //NewThirtySeconds 新用户首次游戏时间 30秒 
    $NewThirtySeconds_query = mysql_query("SELECT count(1)  FROM  deviceid   where date ='$dateTime' and   dayTotalTime between 21 and 30",$db);
    $NewThirtySeconds = mysql_fetch_array($NewThirtySeconds_query);
      //NewSixtySeconds 新用户首次游戏时间 60秒 
    $NewSixtySeconds_query = mysql_query("SELECT count(1)  FROM  deviceid   where date ='$dateTime' and   dayTotalTime between 31 and 60",$db);
    $NewSixtySeconds = mysql_fetch_array($NewSixtySeconds_query);
      //New120Seconds 新用户首次游戏时间 120秒 
    $New120Seconds_query = mysql_query("SELECT count(1)  FROM  deviceid   where date ='$dateTime' and   dayTotalTime between 61 and 120",$db);
    $New120Seconds = mysql_fetch_array($New120Seconds_query);
      //New200Seconds 新用户首次游戏时间 200秒 
    $New200Seconds_query = mysql_query("SELECT count(1)  FROM  deviceid   where date ='$dateTime' and   dayTotalTime between 121 and 200",$db);
    $New200Seconds = mysql_fetch_array($New200Seconds_query);
      //New300Seconds 新用户首次游戏时间 300秒 
    $New300Seconds_query = mysql_query("SELECT count(1)  FROM  deviceid   where date ='$dateTime' and   dayTotalTime between 201 and 300",$db);
    $New300Seconds = mysql_fetch_array($New300Seconds_query);
      //New500Seconds 新用户首次游戏时间 500秒 
    $New500Seconds_query = mysql_query("SELECT count(1)  FROM  deviceid   where date ='$dateTime' and   dayTotalTime between 301 and 500",$db);
    $New500Seconds = mysql_fetch_array($New500Seconds_query);
      //New700Seconds 新用户首次游戏时间 700秒 
    $New700Seconds_query = mysql_query("SELECT count(1)  FROM  deviceid   where date ='$dateTime' and   dayTotalTime between 501 and 700",$db);
    $New700Seconds = mysql_fetch_array($New700Seconds_query);
      //New1000Seconds 新用户首次游戏时间 1000秒 
    $New1000Seconds_query = mysql_query("SELECT count(1)  FROM  deviceid   where date ='$dateTime' and   dayTotalTime between 701 and 1000",$db);
    $New1000Seconds = mysql_fetch_array($New1000Seconds_query);
      //New1500Seconds 新用户首次游戏时间 1500秒 
    $New1500Seconds_query = mysql_query("SELECT count(1)  FROM  deviceid   where date ='$dateTime' and   dayTotalTime between 1001 and 1500",$db);
    $New1500Seconds = mysql_fetch_array($New1500Seconds_query);
      //New2000Seconds 新用户首次游戏时间 2000秒 
    $New2000Seconds_query = mysql_query("SELECT count(1)  FROM  deviceid   where date ='$dateTime' and   dayTotalTime > 1501 ",$db);
    $New2000Seconds = mysql_fetch_array($New2000Seconds_query);

         //TenSeconds 活跃用户当日游戏时间 10秒 
    $TenSeconds_query = mysql_query("SELECT count(1)  FROM  deviceid   where    dayTotalTime between 6 and 10 and date <'$dateTime'",$db);
    $TenSeconds = mysql_fetch_array($TenSeconds_query);
        //TwentySeconds 活跃用户当日游戏时间 20秒 
    $TwentySeconds_query = mysql_query("SELECT count(1)  FROM  deviceid   where   dayTotalTime between 11 and 20 and date <'$dateTime'",$db);
    $TwentySeconds = mysql_fetch_array($TwentySeconds_query);
         //ThirtySeconds 活跃用户当日游戏时间 30秒 
    $ThirtySeconds_query = mysql_query("SELECT count(1)  FROM  deviceid   where  dayTotalTime between 21 and 30 and date <'$dateTime'",$db);
    $ThirtySeconds = mysql_fetch_array($ThirtySeconds_query);
         //SixtySeconds 活跃用户当日游戏时间 60秒 
    $SixtySeconds_query = mysql_query("SELECT count(1)  FROM  deviceid   where   dayTotalTime between 31 and 60 and date <'$dateTime'",$db);
    $SixtySeconds = mysql_fetch_array($SixtySeconds_query);
         //120Seconds 活跃用户当日游戏时间 120秒 
    $_120Seconds_query = mysql_query("SELECT count(1)  FROM  deviceid   where    dayTotalTime between 61 and 120 and date <'$dateTime'",$db);
    $_120Seconds = mysql_fetch_array($_120Seconds_query);
         //200Seconds 活跃用户当日游戏时间 200秒 
    $_200Seconds_query = mysql_query("SELECT count(1)  FROM  deviceid   where   dayTotalTime between 121 and 200 and date <'$dateTime'",$db);
    $_200Seconds = mysql_fetch_array($_200Seconds_query);
         //300Seconds 活跃用户当日游戏时间 300秒 
    $_300Seconds_query = mysql_query("SELECT count(1)  FROM  deviceid   where   dayTotalTime between 201 and 300 and date <'$dateTime'",$db);
    $_300Seconds = mysql_fetch_array($_300Seconds_query);
         //500Seconds 活跃用户当日游戏时间 500秒 
    $_500Seconds_query = mysql_query("SELECT count(1)  FROM  deviceid   where  dayTotalTime between 301 and 500 and date <'$dateTime'",$db);
    $_500Seconds = mysql_fetch_array($_500Seconds_query);
         //700Seconds 活跃用户当日游戏时间 700秒 
    $_700Seconds_query = mysql_query("SELECT count(1)  FROM  deviceid   where   dayTotalTime between 501 and 700 and date <'$dateTime'",$db);
    $_700Seconds = mysql_fetch_array($_700Seconds_query);
         //1000Seconds 活跃用户当日游戏时间 1000秒 
    $_1000Seconds_query = mysql_query("SELECT count(1)  FROM  deviceid   where   dayTotalTime between 701 and 1000 and date <'$dateTime'",$db);
    $_1000Seconds = mysql_fetch_array($_1000Seconds_query);
         //1500Seconds 活跃用户当日游戏时间 1500秒 
    $_1500Seconds_query = mysql_query("SELECT count(1)  FROM  deviceid   where dayTotalTime between 1001 and 1500 and date <'$dateTime'",$db);
    $_1500Seconds = mysql_fetch_array($_1500Seconds_query);
         //2000Seconds 活跃用户当日游戏时间 2000秒 
    $_2000Seconds_query = mysql_query("SELECT count(1)  FROM  deviceid   where   dayTotalTime > 1501  and date <'$dateTime'",$db);
    $_2000Seconds = mysql_fetch_array($_2000Seconds_query);


$sql="insert INTO deviceid_report_fiveminutes (date,
          NewTenSeconds,
          NewTwentySeconds,
          NewThirtySeconds,
          NewSixtySeconds,
          New120Seconds,
          New200Seconds,
          New300Seconds,
          New500Seconds,
          New700Seconds,
          New1000Seconds,
          New1500Seconds,
          New2000Seconds,
          TenSeconds,
          TwentySeconds,
          ThirtySeconds,
          SixtySeconds,
          _120Seconds,
          _200Seconds,
          _300Seconds,
          _500Seconds,
          _700Seconds,
          _1000Seconds,
          _1500Seconds,
          _2000Seconds
          ) 
                  VALUES('$dateTime',
                '$NewTenSeconds[0]',
                '$NewTwentySeconds[0]',
                '$NewThirtySeconds[0]',
                '$NewSixtySeconds[0]',
                '$New120Seconds[0]',
                '$New200Seconds[0]',
                '$New300Seconds[0]',
                '$New500Seconds[0]',
                '$New700Seconds[0]',
                '$New1000Seconds[0]',
                '$New1500Seconds[0]',
                '$New2000Seconds[0]',
                '$TenSeconds[0]',
                '$TwentySeconds[0]',
                '$ThirtySeconds[0]',
                '$SixtySeconds[0]',
                '$_120Seconds[0]',
                '$_200Seconds[0]',
                '$_300Seconds[0]',
                '$_500Seconds[0]',
                '$_700Seconds[0]',
                '$_1000Seconds[0]',
                '$_1500Seconds[0]',
                '$_2000Seconds[0]'
                )";
$query= @mysql_query($sql,$db) or die(mysql_error());  

//}
mysql_close($db);
//mysql_close($db2);
?>
